package 
{
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
	
	public class ButtonScrolling extends BaseScrolling
	{			
		public var fScrollWidth: Number;
	
		private var LeftScroll: TControl;
		private var RightScroll: TControl;	
		
		public override function get ScrollWidth(): int
		{
			return fScrollWidth;
		}
				
		private function LeftScrollClick(e:MouseEvent): void
		{
			if (LeftScroll.Enabled)
			{
				if (fCont.ScrollByOneItem)
					fCont.Move2Left()
				else
					fCont.List2Left();
			}
		}
		
		private function RightScrollClick(e:MouseEvent): void
		{
			if (RightScroll.Enabled)
			{
				if (fCont.ScrollByOneItem)
					fCont.Move2Right()
				else
					fCont.List2Right();
			}
		}
	
		private function RotateScroll(C: TControl): void
		{
			if (fCont.Vert)
			{
				C.Ctrl.rotation = 90;
				C.X = fCont.X + fCont.Width - fCont.BorderWidth;
			}
		}

		public override function UpdateScrollView(): void
		{
			LeftScroll.Enabled = fCont.FirstItemIndex > 0;
			if (fCont.Ctrls.length > 0)
				RightScroll.Enabled = !(fCont.Ctrls[fCont.Ctrls.length - 1].Visible)
			else
				RightScroll.Enabled = false;		
		}
		
		public override function SetScrollVisible(v: Boolean): void
		{
			LeftScroll.Visible = v;
			RightScroll.Visible = v;			
		}
		
		public override function Init(): void
		{
			LeftScroll = new InvControl(TKNRes.left_scroll, fCont.fParent, fCont.X + fCont.BorderWidth, fCont.Y + fCont.BorderWidth);
			RotateScroll(LeftScroll);
			fCont.CalcBonds(LeftScroll);
			LeftScroll.addEventListener(MouseEvent.CLICK, LeftScrollClick);
		
			if (fCont.Vert)
				fScrollWidth = fCont.BorderWidth + LeftScroll.Height
			else
				fScrollWidth = fCont.BorderWidth + LeftScroll.Width;
		
			RightScroll = new InvControl(TKNRes.right_scroll, fCont.fParent, fCont.X + fCont.Width - fScrollWidth, fCont.Y + fCont.BorderWidth);
			RotateScroll(RightScroll);
			fCont.CalcBonds(RightScroll);
			RightScroll.addEventListener(MouseEvent.CLICK, RightScrollClick);
		
			if (fCont.Vert)
				RightScroll.Y = fCont.Height - fScrollWidth + fCont.Y;
				
			fCont.RepaintChilds();
		}

		public function ButtonScrolling(Cont: TBaseContainer): void
		{
			super(Cont);
		}
	}
	
}